/****************************************
*  This file created using "Writer B"   *
*      a program written by CTonk       *
*          ctonk87@hotmail.com          *
*     [timestamp 02/20/06  12:50:06]    *
****************************************/

// Room.cpp

#ifndef CPP_ROOM
#define CPP_ROOM

#include "Room.h"


// Constructors...
Room::Room()
{
	_vnum = 0;
	_area = 0;
	_sector = 0;
	_name = new char[50];
	for ( int x=0; x < 50; x++ )
		_name[x] = '\0';
	_desc = new char[MAX_INPUT_BUFFER];
	for ( int x=0; x < MAX_INPUT_BUFFER; x++ )
		_desc[x] = '\0';
	_descolor = new char[3];
	strcpy( _descolor, "{x" );
	_exit = new Exit[6];
	_noexit = true;
}

Room::Room( Room& it )
{
	_vnum = it._vnum;
	_area = it._area;
	_sector = it._sector;
	for ( int x=0; x < 50; x++ )
		_name[x] = it._name[x];
	for ( int x=0; x < MAX_INPUT_BUFFER; x++ )
		_desc[x] = it._desc[x];
	_descolor[1] = it._descolor[1];
	for ( int x=0; x < 6; x++ )
		_exit[x] = it._exit[x];
	_noexit = it.NoExits();
}

Room::~Room()
{
	delete[] _name;
	delete[] _desc;
	delete[] _exit;
}

// Operators...
Room& Room::operator = ( Room& it )
{
	_vnum = it._vnum;
	_area = it._area;
	_sector = it._sector;
	for ( int x=0; x < 50; x++ )
		_name[x] = it._name[x];
	for ( int x=0; x < MAX_INPUT_BUFFER; x++ )
		_desc[x] = it._desc[x];
	_descolor[1] = it._descolor[1];
	for ( int x=0; x < 6; x++ )
		_exit[x] = it._exit[x];
	_noexit = it.NoExits();
	return *this;
}

// Public accessor methods...
int Room::GetVnum()
{
	return _vnum;
}

void Room::SetVnum( int vnum )
{
	_vnum = vnum;
}

int Room::GetArea()
{
	return _area;
}

void Room::SetArea( int area )
{
	_area = area;
}

int Room::GetSector()
{
	return _sector;
}

void Room::SetSector( int sector )
{
	_sector = sector;
	switch ( _sector )
	{
		case  0: _descolor[1] = 'x'; break;
		case  1: _descolor[1] = 'G'; break;
		case  2: _descolor[1] = 'y'; break;
		case  3: _descolor[1] = 'w'; break;
		case  4: _descolor[1] = 'g'; break;
		case  5: _descolor[1] = 'x'; break;
		case  6: _descolor[1] = 'x'; break;
		case  7: _descolor[1] = 'Y'; break;
		case  8: _descolor[1] = 'w'; break;
		case  9: _descolor[1] = 'W'; break;
		case 10: _descolor[1] = 'w'; break;
		case 11: _descolor[1] = 'w'; break;
		case 12: _descolor[1] = 'B'; break;
		default: _descolor[1] = 'x'; break;
	}
	return;
}

char* Room::GetName( void )
{
	return _name;
}

char Room::GetName( int x )
{
	return _name[x];
}

void Room::SetName( char* val )
{
	strcpy( _name, val );
	return;
}

void Room::SetName( const char* val )
{
	strcpy( _name, val );
	return;
}

void Room::SetName( int x, char val )
{
	_name[x] = val;
}

char* Room::GetDesc( void )
{
	return _desc;
}

char Room::GetDesc( int x )
{
	return _desc[x];
}

void Room::SetDesc( char* val )
{
	strcpy( _desc, val );
	return;
}

void Room::SetDesc( const char* val )
{
	strcpy( _desc, val );
	return;
}

void Room::SetDesc( int x, char val )
{
	_desc[x] = val;
}

char* Room::GetDescolor()
{
	return _descolor;
}

Exit* Room::GetExit( void )
{
	return _exit;
}

Exit& Room::GetExit( int x )
{
	return _exit[x];
}

void Room::SetNoexit( bool noexit )
{
	_noexit = noexit;
	return;
}

bool Room::NoExits()
{
	return _noexit;
}

Magiclist< Creature* >& Room::GetClist()
{
	return _clist;
}

void Room::Add( Creature* c )
{
	_clist.GetList().push_back( c );
	return;
}

void Room::Remove( Creature* c )
{
	_clist.GetList().remove( c );
	return;
}

bool Room::There( Creature* c )
{
	for ( std::list< Creature* >::iterator IT = _clist.GetList().begin(); IT != _clist.GetList().end(); IT++ )
		if ( c == (*IT) )
			return true;
	return false;
}

Creature* Room::GetC( int x )
{
	return _clist[x];
}

Magiclist< Object* >& Room::GetOlist()
{
	return _olist;
}

void Room::Add( Object* obj )
{
	_olist.Add( obj );
	return;
}

void Room::Remove( Object* obj )
{
	_olist.GetList().remove( obj );
	return;
}

bool Room::There( Object* obj )
{
	for ( std::list< Object* >::iterator IT = _olist.GetList().begin(); IT != _olist.GetList().end(); IT++ )
		if ( obj == (*IT) )
			return true;
	return false;
}

Object* Room::GetO( int number )
{
	return _olist[ number ];
}

// Other methods...
void Room::Display( std::ostream& out )
{
	out << "-Room-";
	out << "\nVnum: " << _vnum;
	out << "\nArea: " << _area;
	out << "\nSector: " << _sector;
	out << "\nName: " << _name;
	out << "\nDesc: " << _desc << '\n';
	out << "\nExit: ";
	for ( int x=0; x < 6; x++ )
	{
		_exit[x].Display( out );
		out << '\n';
	}
	return;
}

void Room::Display( std::string& out )
{
	out << "-Room-";
	out << "\nVnum: " << _vnum;
	out << "\nArea: " << _area;
	out << "\nSector: " << _sector;
	out << "\nName: " << _name;
	out << "\nDesc: " << _desc << '\n';
	for ( int x=0; x < 6; x++ )
	{
		_exit[x].Display( out );
		out << '\n';
	}
	return;
}

void Room::Save( std::ofstream& save ) {
	save << "\n**ROOM\n";
	save << _vnum << ' ' << _area << ' ' << _sector << '\n';
	save << _name << '\n';
	save << "DESCRIPTION!!!!!!!\n";
	for ( int x=0; x < 6; x++ )
		_exit[x].Save( save );
	return;
}

void Room::Load( std::ifstream& load ) {

	load >> _vnum >> _area >> _sector;
	load.get(); load.getline( _name, 500 );
	load.getline( _desc, MAX_INPUT_BUFFER, '~' );

	for ( int x=0; x < 6; x++ )
		this->_exit[x].Load( load );
		if ( this->_exit[x].GetThere() )
			this->SetNoexit( false );

	return;
}



#endif // #ifndef CPP_ROOM
